package com.github.prontera.service;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.prontera.domain.Consume;
import com.github.prontera.domain.enums.ConsumeLevelTypeEnum;
import com.github.prontera.domain.enums.ConsumeSmallTypeEnum;
import com.github.prontera.domain.enums.ConsumeTypeEnum;
import com.github.prontera.persistence.ConsumeMapper;
import com.github.prontera.persistence.CrudMapper;

/**
 * 消费记录
 */
@Service
public class ConsumeService extends CrudServiceImpl<Consume> {

	@Autowired
	private ConsumeMapper mapper;
	
	@Autowired
	public ConsumeService(CrudMapper<Consume> mapper) {
		super(mapper);
	}
	
	/**
	 * 下线每月收入
	 */
	public int monthSubordinateTalentConsume(){
		return mapper.monthSubordinateTalentConsume();
	};
	
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean insertConsume(Long clientId, ConsumeSmallTypeEnum consumeType, String lable, ConsumeLevelTypeEnum levelType,Integer myBean, BigDecimal amount,  ConsumeTypeEnum type,BigDecimal baseAmount) {
		Consume consume = new Consume();
		consume.setAmount(amount);
		consume.setClientId(clientId);
		consume.setConsumeType(consumeType);
		consume.setLable(lable);
		consume.setLevelType(levelType);
		consume.setType(type);
		consume.setBaseAmount(baseAmount);
		consume.setMyBean(myBean);
		if (mapper.insert(consume) > 0) {
			return true;
		}
		return false;
	}

}
